package com.xuecheng.content.feignclient;

import com.xuecheng.content.config.MultipartSupportConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 26455
 * @version 1.0
 * @description TODO
 * @date 2023/2/20 15:25
 */
@FeignClient(value = "media-api", configuration = MultipartSupportConfig.class, fallback = MediaServiceClient.MediaServiceClientFallback.class)
public interface MediaServiceClient {

    @RequestMapping(value = "/media/upload/coursefile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String uploadFile(@RequestPart("filedata") MultipartFile upload, @RequestParam(value = "folder", required = false) String folder, @RequestParam(value = "objectName", required = false) String objectName);

    @Slf4j
    @Component
    class MediaServiceClientFallback implements MediaServiceClient {

        @Override
        public String uploadFile(MultipartFile upload, String folder, String objectName) {
            log.debug("远程调用文件上传失败");
            return null;
        }
    }
}
